<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Nc extends CI_Controller{
    function __construct()
    {
      parent::__construct();

      if( !$this->session->userdata('isLoggedIn') ) {
          redirect('/login/show_login');
      }
    }
    public function nc_manager(){

        $managerList = array("nc_key"=>"KEY管理","nc_policy"=>"银行策略管理","nc_port"=>"NC监听端口管理");
        $bankName = array("","工行","农行","招行","建行","中行","交行","兴业","平安","中信","光大","民生","浦发","广发","邮储","结算中心");
        $bankIdc = array("","腾大","沙河");
        $bankProto = array("","TCP","UDP");
        $data['sidebar_type'] = "nc";
        $data['sidebar_list'] = $managerList;
        $data['is_admin'] = $this->session->userdata('isadmin');
        $this->load->view('nc',$data);
    }
    public function nc_check($nc_flag=null){
        $managerList = array("nc_key"=>"KEY管理","nc_policy"=>"银行策略管理","nc_port"=>"NC监听端口管理");
        $bankName = array("","工行","农行","招行","建行","中行","交行","兴业","平安","中信","光大","民生","浦发","广发","邮储","结算中心");
        $bankIdc = array("","腾大","沙河");
        $bankProto = array("","TCP","UDP");
        $sc = array(); //search conditions array
        $retSc = array();
        $result=null;
        $this->load->helper('form');
        $this->load->model('nc_m');
        $data['sidebar_type'] = "nc";
        $data['sidebar_list'] = $managerList;
        $data['is_admin'] = $this->session->userdata('isadmin');
        $data['nc_flag'] = $nc_flag;
        $data['bank_name'] = $bankName;
        $data['bank_proto'] = $bankProto;
        $data['bank_idc'] = $bankIdc;
        if($nc_flag=="nc_key"){
            $sc['key_bank_type']=$this->input->post('key_bank_type');
            $sc['key_bank_name']=$this->input->post('key_bank_name');
            $sc['key_user']=$this->input->post('key_user');
            $sc['key_number']=$this->input->post('key_number');
            $sc['key_cert_number']=$this->input->post('key_cert_number');
            $sc['key_keeper']=$this->input->post('key_keeper');
            $sc['key_cert_starttime']=$this->input->post('key_cert_starttime');
            $sc['key_cert_endtime']=$this->input->post('key_cert_endtime');
            $sc['key_ip']=$this->input->post('key_ip');
            $retSc=$this->getNotNullCondition($sc);
            if($retSc)
                $result=$this->nc_m->get_key_detail($retSc);
        }else if($nc_flag=="nc_policy"){
            $sc['policy_bank_type']=$this->input->post('policy_bank_type');
            $sc['policy_bank_name']=$this->input->post('policy_bank_name');
            $sc['policy_bank_ip'] = $this->input->post('policy_bank_ip');
            $sc['policy_bank_port']=$this->input->post('policy_bank_port');
            $sc['policy_bank_proto']=$this->input->post('policy_bank_proto');
            $sc['policy_bank_idc'] = $this->input->post('policy_bank_idc');
            $sc['policy_bank_nat'] = $this->input->post('policy_bank_nat');
            $sc['policy_bank_line'] = $this->input->post('policy_bank_line');
            $retSc=$this->getNotNullCondition($sc);
            if($retSc)
               $result=$this->nc_m->get_policy_detail($retSc); 
        }else if($nc_flag=="nc_port"){
            $sc['nc_bank_type']=$this->input->post('nc_bank_type');
            $sc['nc_bank_name']=$this->input->post('nc_bank_name');
            $sc['nc_listen_port']=$this->input->post('nc_listen_port');
            $retSc=$this->getNotNullCondition($sc);
            if($retSc)
                $result=$this->nc_m->get_port_detail($retSc);
        }
        if(is_array($result) && count($result) >0 )
            $data['search_result']=$result;
        else
            $data['search_result']=$retSc;
        $this->load->view('nc',$data);
    }
    public function getNotNullCondition($searchConditions){
        $retArr=array();
        foreach($searchConditions as $key=>$val){
            if($val)
                $retArr[$key]=$val;
        }
        return $retArr;
    }
}

